package cn.edu.ctbu.controller.user;

import cn.edu.ctbu.DTO.OrderDTO;
import cn.edu.ctbu.DTO.PaySuccessDTO;
import cn.edu.ctbu.VO.OrderDetailVO;
import cn.edu.ctbu.VO.PayOrdersVO;
import cn.edu.ctbu.entity.OrderDetail;
import cn.edu.ctbu.result.Result;
import cn.edu.ctbu.service.IOrdersService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("用户端订单")
@RequestMapping("/user/orders")
public class OrdersController {

    @Autowired
    IOrdersService iOrdersService;

    /**
     * 提交订单
     */
    @PostMapping("/submit")
    public Result<String> postOrder(@RequestBody OrderDTO dto){
        String number=iOrdersService.postOrder(dto);
        return  Result.success(number);
    }

    /**
     * 根据订单号查找订单
     */
    @GetMapping
    public Result<PayOrdersVO> getOrders(String number){
        PayOrdersVO orders=iOrdersService.getByNumber(number);
        return Result.success(orders);
    }
    /**
     * 获得全部订单
     */
    @GetMapping("/list")
    public Result<List<OrderDetailVO>> getOrdersList(String search){
        List<OrderDetailVO> orders=iOrdersService.getOrdersList(search);
        return Result.success(orders);
    }

    /**
     *订单支付成功
     */
    @PostMapping("/pay")
    public Result paySuccess(@RequestBody PaySuccessDTO dto){
        iOrdersService.paySuccess(dto);
        return Result.success();
    }
    /**
     * 获得订单菜品信息
     */
    @GetMapping("/detail")
    public Result<List<OrderDetail>> getOrdersDetail(String number){
        List<OrderDetail> orders=iOrdersService.getOrdersDetailByNumber(number);
        return Result.success(orders);
    }

    /**
     * 取消订单
     */
    @GetMapping("/cancel")
    public Result cancelOrders(String number){
        iOrdersService.cancelOrders(number);
        return Result.success();
    }
    /**
     * 申请退款
     */
    @GetMapping("/refund")
    public Result refundOrders(String number){
        iOrdersService.refundOrders(number);
        return Result.success();
    }


    /**
     * 催单
     */
    @GetMapping("/remind")
    @ApiOperation("催单")
    public Result remind(Long id){
        iOrdersService.remind(id);
        return Result.success();
    }


}
